<template>
  <!-- Excel 导入功能组件 -->
  <upload-excel :on-success="handleSuccess" />

</template>

<script>
import { formatExcelDate } from '@/utils/index.js'
export default {
  name: 'Excel',
  methods: {
    // 导入成功以后的回调函数
    handleSuccess({ results, header }) {
      console.log(results)
      const userRelations = {
        '入职日期': 'timeOfEntry',
        '手机号': 'mobile',
        '姓名': 'username',
        '转正日期': 'correctionTime',
        '工号': 'workNumber',
        '部门': 'departmentName',
        '聘用形式': 'formOfEmployment'

      }
      const newArr = []
      results.forEach(item => {
        const newobj = {}
        Object.keys(item).forEach(key => {
          const enKey = userRelations[key]
          if (enKey === 'timeOfEntry' || enKey === 'correctionTime') {
            const time = formatExcelDate(item[key])
            newobj[enKey] = time
          } else {
            newobj[enKey] = item[key]
          }
        })
        newArr.push(newobj)
      })
      console.log(newArr)
    }

  }
}
</script>

<style lang="scss" scoped></style>
